﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;

namespace Store.Models
{
    public class StoreDBContext : DbContext
    {
        public StoreDBContext()
        {

        }
        public StoreDBContext(DbContextOptions<StoreDBContext> options):base(options)
        {

        }
        //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        //{
        //    optionsBuilder
        //        .UseLoggerFactory(loggerFactory)
        //        .UseSqlServer(@"server=.;database=StoreDB;uid=sa;pwd=123456");
        //}

        public DbSet<Favorite> Favorites { get; set; }
        public DbSet<Goods> Goods { get; set; }
        public DbSet<GoodsEvaluate> GoodsEvaluates { get; set; }
        public DbSet<GoodsType> GoodsTypes { get; set; }
        public DbSet<Order> Orders { get; set; }
        public DbSet<OrderInfo> OrderInfos { get; set; }
        public DbSet<ShippingAddress> ShippingAddress { get; set; }
        public DbSet<ShoppingTrolley> ShoppingTrolleys { get; set; }
        public DbSet<User> Users { get; set; }

        public static readonly ILoggerFactory loggerFactory =
             LoggerFactory.Create(builder => 
             { 
                 builder.AddFilter((category,level)=>
                        category == DbLoggerCategory.Database.Command.Name
                        && level == LogLevel.Information
                 ).AddConsole(); 
             });
    }
}
